home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / JAVA_UTL / HYPERPRO / SRC / PVS / HYPERBOL / HYPERCYR.JAV < prev    next >
Encoding:
Text File  |  1996-09-14  |  3.4 KB  |  122 lines

  1. package PVS.Hyperbolic;
  2. //
  3. // Copyright (C) 1996 by Vladimir Bulatov <V.Bulatov@ic.ac.uk>.  
  4. //        All rights reserved.
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions
  8. // are met:
  9. // 1. Redistributions of source code must retain the above copyright
  10. //    notice, this list of conditions and the following disclaimer.
  11. // 2. Redistributions in binary form must reproduce the above copyright
  12. //    notice, this list of conditions and the following disclaimer in the
  13. //    documentation and/or other materials provided with the distribution.
  14. //
  15. // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. // ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19. // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. // SUCH DAMAGE.
  26.  
  27.  
  28. import java.awt.Color;
  29. import PVS.Utils.MathExt;
  30.  
  31. public class HyperCyrcle extends Object implements HyperObject,Cloneable{
  32.  
  33.   public Color color = Color.black;
  34.   public Complex z;
  35.   public double radius;
  36.   public boolean hollow = false;
  37.   public double eradius; // euclidean radius
  38.   public double ecenterx, ecentery;// euclidean positions
  39.   
  40.   boolean wasMoved = true;
  41.  
  42.   public HyperCyrcle(){
  43.     z = new Complex();
  44.   }
  45.  
  46.   public HyperCyrcle(Complex z, double radius, Color color){
  47.     this(z, radius, color, true);
  48.   }
  49.  
  50.   public HyperCyrcle(Complex z, double radius, Color color, boolean hollow){
  51.     this.z = new Complex(z);
  52.     this.color = color;
  53.     this.radius = radius;
  54.     this.hollow = hollow;
  55.   }
  56.  
  57.   public void place(double x, double y){
  58.     z.set(x,y);
  59.     wasMoved = true;
  60.   }
  61.  
  62.   public void doTranslate(Complex p){
  63.     Hyperbolic.doTranslate(z,p);
  64.     wasMoved = true;
  65.   }
  66.   
  67.   public void doRotate(Complex teta){
  68.     z.mul(teta);
  69.     wasMoved = true;
  70.   }
  71.  
  72.   public void doTransform(HTransform t){
  73.     Hyperbolic.doTransform(z,t);
  74.     wasMoved = true;
  75.   }
  76.  
  77.   public void reflect(Arc arc){
  78.     Hyperbolic.reflect(z,arc);     
  79.     wasMoved = true;
  80.   }
  81.  
  82.   // temporary variables
  83.   private static Complex z1 = new Complex(), z2 = new Complex();
  84.  
  85.   public void draw(Graphics2d g){
  86.     if(wasMoved){
  87.       // euclidean radius 
  88.       double erad = MathExt.tanh(0.5*radius);  
  89.       double zlen = z.abs();
  90.       // move cyrcle in place
  91.       if(zlen != 0.0){
  92.     z1.set(erad*z.re/zlen,erad*z.im/zlen);  
  93.     z2.set(-erad*z.re/zlen,-erad*z.im/zlen);
  94.     Hyperbolic.doTranslate(z1,z);
  95.     Hyperbolic.doTranslate(z2,z);
  96.     z1.add(z2); z1.mul(0.5); 
  97.     z2.sub(z1);
  98.     // euclidean radius of moved cyrcle
  99.     eradius = z2.abs();
  100.     ecenterx = z1.re;
  101.     ecentery = z1.im;
  102.       } else {
  103.     eradius = erad;
  104.     ecenterx = z.re;
  105.     ecentery = z.im;
  106.       }
  107.       wasMoved = false;
  108.     }
  109.     g.setColor(color);
  110.     if(hollow)      
  111.       g.drawCyrcle(ecenterx,ecentery,eradius);
  112.     else 
  113.       g.fillCyrcle(ecenterx,ecentery,eradius);
  114.   }
  115.  
  116.   public HyperObject getCopy(){
  117.     return new HyperCyrcle(z,radius,color);
  118.   }
  119.  
  120. }
  121.  
  122.